<?php

namespace app\admin\controller;

use app\admin\model\User as model_user;
use app\admin\model\Litestoreshop as model_shop;
use app\admin\model\Usermoney as model_money;
use app\admin\model\Deposit as model_depost;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Dashboard;

    }

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');

        //会员model
        $model_user=new model_user();
        //总会员数查询
        $usercount=$model_user->count();

        //商家model
        $model_shop=new model_shop();
        //总商家查询
        $shopcount=$model_shop
            ->with(['user'])
            ->where(['user.id'=>array('gt',0)])
            ->count();


        $order=$this->model->play_priceorder();

        $shopordercount=$order['shopordercount']; //总订单

        $todayordersum=$order['todayordersum']; //当天订单总金额

        $yearordersum=$order['yearordersum']; //当年订单总金额

        $todaycontributionsum=$order['todaycontributionsum']; //当天贡献值

        $yearcontributionsum=$order['yearcontributionsum']; //当年贡献值

        $yearbonus=$order['yearbonus']; //当年红包

        $dbonus=$order['dbonus']; //当天红包

        $yeardepost=$order['yeardepost']; //当年提现金额

        $yeardepostaudit=$order['yeardepostaudit']; //当年提现进行金额

        $ddepostaudit=$order['ddepostaudit']; //当天提现进行金额

        $ddepost=$order['ddepost']; //当天提现金额

        $this->view->assign([
            'totaluser'        => $usercount,
            'totalviews'       => 219390,
            'totalorder'       => $shopcount,
            'totalorderamount' => $shopordercount, //总订单
            'todayuserlogin'   => 321,
            'todayusersignup'  => 430,
            'todayorder'       => $todayordersum, //当天订单总金额
            'yearorder'       => $yearordersum,//当年订单总金额
            'todaycontributionr'       => $todaycontributionsum, //当天贡献值
            'yearcontributionr'       => $yearcontributionsum,//当年贡献值
            'yearbonus'       => $yearbonus,//当年红包
            'dbonus'       => $dbonus,//当天红包
            'yeardepost'       => $yeardepost,//当年提现金额
            'yeardepostaudit'=>$yeardepostaudit,//当年提现进行金额
            'ddepost'       => $ddepost,//当天提现金额
            'ddepostaudit'=>$ddepostaudit,//当天提现进行金额
            'unsettleorder'    => 132,
            'sevendnu'         => '80%',
            'sevendau'         => '32%',
            'paylist'          => $paylist,
            'createlist'       => $createlist,
            'addonversion'       => $addonVersion,
            'uploadmode'       => $uploadmode
        ]);

        return $this->view->fetch();
    }


}
